home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2011 May / PC Advisor 190 E.iso / pc / ESSENTIALS / VLC Media Player 1.1 / vlc-1.1.5-win32.exe / lua / playlist / anevia_xml.lua < prev    next >
Encoding:
Text File  |  2010-11-13  |  3.5 KB  |  87 lines

  1. --[[
  2.  Parse list of available streams on Anevia servers.
  3.  The URI http://ipaddress/ws/Mgmt/* describes a list of
  4.  available streams on the server.
  5.  
  6.  Copyright ┬⌐ 2009 M2X BV
  7.  
  8.  Authors: Jean-Paul Saman <jpsaman@videolan.org>
  9.  
  10.  This program is free software; you can redistribute it and/or modify
  11.  it under the terms of the GNU General Public License as published by
  12.  the Free Software Foundation; either version 2 of the License, or
  13.  (at your option) any later version.
  14.  
  15.  This program is distributed in the hope that it will be useful,
  16.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  GNU General Public License for more details.
  19.  
  20.  You should have received a copy of the GNU General Public License along
  21.  with this program; if not, write to the Free Software Foundation, Inc.,
  22.  51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. --]]
  24.  
  25. -- Probe function.
  26. function probe()
  27.     return vlc.access == "http"
  28.         and string.match( vlc.path, "/ws/Mgmt/" )
  29. end
  30.  
  31. -- Fake readline. Read <>(..*)</> whole, otherwise pretend a newline.
  32. -- In lua, indices are from 1, not 0, so no +1 needed.
  33. function readline()
  34.     local n = string.find(vlc.peek(998),"><") -- A random large number
  35.     return n and vlc.read(n) or vlc.readline()
  36. end
  37.  
  38. -- Parse function.
  39. function parse()
  40.     local p = {}
  41.     local line
  42.     _,_,server = string.find( vlc.path, "(.*)/ws/Mgmt/" )
  43.     while true do
  44.         line = readline()
  45.         if not line then break end
  46.         if string.match( line, "<struct name=\"stream\">" ) then
  47.             while true do
  48.                 line = readline()
  49.                 if not line then break end
  50.                 if string.match( line, "<field name=\"name\">" ) then
  51.                     _,_,name = string.find( line, "name=\"name\">(.*)</field>" )
  52.                 end
  53.                 if string.match( line, "<choice name=\"destination\">" ) then
  54.                     while true do
  55.                         line = readline()
  56.                         if not line then break end
  57.                         if string.match( line, "<struct name=\"(.*)\">" ) then
  58.                             _,_,protocol = string.find( line, "<struct name=\"(.*)\">" )
  59.                             while true do
  60.                                 line = readline()
  61.                                 if not line then break end
  62.                                 if string.match( line, "<field name=\"address\">(.*)</field>" ) then
  63.                                     _,_,address = string.find( line, "<field name=\"address\">(.*)</field>" )
  64.                                 end
  65.                                 if string.match( line, "<field name=\"port\">(.*)</field>" ) then
  66.                                     _,_,port = string.find( line, "<field name=\"port\">(.*)</field>" )
  67.                                 end
  68.                                 -- end of struct tag
  69.                                 if string.match( line, "</struct>" ) then
  70.                                     media = tostring(protocol) .. "://@" .. tostring(address) .. ":" .. tostring(port)
  71.                                     table.insert( p, { path = media; name = name, url = media } )
  72.                                     break
  73.                                 end
  74.                             end
  75.                         end
  76.                         if not line then break end
  77.                         -- end of choice tag
  78.                         if string.match( line, "</choice>" ) then break end
  79.                     end
  80.                 end
  81.             end
  82.         end
  83.  
  84.     end
  85.     return p
  86. end
  87.